<template>
  <div class="zh-legend" v-show="isShowFlag">
    <div class="legend-word">
      图例
     <!-- <i class="el-icon-caret-right"></i>-->
    </div>
    <ul>
      <li v-for="(item,index) in data" :key="index">
        <i class="bh-icon" :style="`background-color: ${item.color}`"></i>
        <span>{{item.name}}</span>
      </li>
    </ul>
  </div>
</template>
<script lang="ts">
import { Component, Vue , Watch } from 'vue-property-decorator';
import MapCommon from '@/util/MapCommon';

@Component({
  mixins: [MapCommon]
})
export default class Legend extends Vue {
  private data = [
    { name: '>=10000', color: '#71161d'  },
    { name: '1000-9999', color: '#cb2b2f'},
    { name: '500-999', color: '#e55a4e'},
    { name: '100-499', color: '#f49d82'},
    { name: '1-99', color: '#f9ead3'}
  ];

  // 监听外部code改变
    get isShowFlag() {
    const tuliType : any = this.$store.state.ZhtsModule.tuliType;
    const state : boolean =  tuliType === 'yiqingClass' || tuliType === 'renkouClass';
    return state;
  }

  @Watch("$store.state.ZhtsModule.tuliType")
  @Watch("$store.state.cityListModule.checkedCityObj.id",{deep: true})
  private gettuliType() {
    const tuliType : any = this.$store.state['ZhtsModule' as any].tuliType;
    const districtCode : string =  this.$store.state['cityListModule' as any].checkedCityObj.id;
    const citytypeNum :number = this.getDistrictLevel(districtCode);
    const dataArr1: any = {
      0 :[ // citytypeNum 0 -- 全国
        { name: '>=10000', color: '#71161d'  },
        { name: '1000-9999', color: '#cb2b2f'},
        { name: '500-999', color: '#e55a4e'},
        { name: '100-499', color: '#f49d82'},
        { name: '1-99', color: '#f9ead3'}
      ],
      1 :[ // 1 -- 省
        { name: '>=1000', color: '#71161d'  },
        { name: '500-999', color: '#cb2b2f'},
        { name: '100-499', color: '#e55a4e'},
        { name: '10-99', color: '#f49d82'},
        { name: '1-9', color: '#f9ead3'}
      ],
      2 :[ // 2 -- 市
        { name: '>=1000', color: '#71161d'  },
        { name: '500-999', color: '#cb2b2f'},
        { name: '100-499', color: '#e55a4e'},
        { name: '10-99', color: '#f49d82'},
        { name: '1-9', color: '#f9ead3'}
      ],
      3 :[ // 3---区县
        { name: '>=1000', color: '#71161d'  },
        { name: '500-999', color: '#cb2b2f'},
        { name: '100-499', color: '#e55a4e'},
        { name: '10-99', color: '#f49d82'},
        { name: '1-9', color: '#f9ead3'}
      ],
    };
    if (tuliType === 'yiqingClass') {
      this.data = []
      this.data = dataArr1[citytypeNum];
    } else if (tuliType === 'renkouClass') {
      this.data = []
      this.data = [
        { name: '3000-4000', color: '#08519C' },
        { name: '2000-2999', color: '#3182BD'},
        { name: '1000-1999', color: '#6BAED6'},
        { name: '500-999', color: '#BDD7E7'},
        { name: '0-499', color: '#EFF3FF'}
      ];
    }else {
      this.data = [];
    }
  }

  /**
   * 根据行政区划编码获取行政区划等级
   * @param districtCode 行政区划编码
   */
  private getDistrictLevel(districtCode: string): number {

    // 0 -- 全国 ; 1 -- 省;2 -- 市;  3---区县
    // 直辖市按照市做特殊处理

    switch (true) {
      case /[0]{6}/.test(districtCode):
        return 0;
      case /(11|12|31|50)[0]{4}/.test(districtCode):
        return 2;
      case /[1-9]{2}[0]{4}/.test(districtCode):
        return 1;
      case /[1-9]{2}([1-9]\d{1}|\d{1}[1-9]){1}[0]{2}/.test(districtCode):
        return 2;
      default:
        return 3;
    }
  }
}
</script>
<style lang="less" scoped>
.zh-legend {
  width: 165px;
  height: 180px;
  padding-top: 35px;
  background: url('../../../../assets/img/legend/legend_bg.png') no-repeat 0 0;
  background-size: 100% 100%;
  background-color: transparent;
  position: absolute;
  bottom: 40px;
  left: -170px;
  .legend-word {
    position: absolute;
    top: -13px;
    right: 11px;
    font-size: 16px;
    line-height: 32px;
    color: #fff;
    text-align: center;
    background: url('../../../../assets/img/legend/legend_word.png') no-repeat 0
      0;
    background-size: 100% 100%;
    width: 120px;
    height: 32px;
    border: 1px solid #00ffff;
    border-radius: 18px;
    i {
      color: #00ffff;
    }
  }
  li {
    position: relative;
    list-style: none;
    //cursor: pointer;
    .bh-icon {
      width: 16px;
      height: 16px;
      border-radius: 2px;
      display: inline-block;
      vertical-align: middle;
      position: absolute;
      left: -7px;
      top: 50%;
      margin-top: -8px;
    }
    span {
      font-size: 18px;
      height: 30px;
      line-height: 30px;
      color: #fff;
      display: inline-block;
      padding-left: 20px;
    }
    i {
      width: 30px;
      height: 30px;
      display: inline-block;
      position: absolute;
      left: 25px;
      margin-top: 6px;
    }
  }
  :nth-of-type(1) .teamIcon {
    background: url('../../../../assets/img/legend/bendi.png') no-repeat;
    background-size: 100% 100%;
  }
  :nth-of-type(2) .teamIcon {
    background: url('../../../../assets/img/legend/difang.png') no-repeat;
    background-size: 100% 100%;
  }
  :nth-of-type(3) .teamIcon {
    background: url('../../../../assets/img/legend/budui.png') no-repeat;
    background-size: 100% 100%;
  }
  li:nth-child(2) {
    .legend-icon {
      background: url('../../../../assets/img/legend/icon2.png') no-repeat;
    }
  }
  li:nth-child(3) {
    .legend-icon {
      background: url('../../../../assets/img/legend/icon3.png') no-repeat;
    }
  }
  header {
    background: url('../../../../assets/img/legend/close.png') no-repeat;
    background-size: 100% 100%;
    width: 50px;
    height: 50px;
    position: absolute;
    bottom: 138px;
    right: 272px;
    z-index: 22;
    cursor: pointer;
  }
  .content-list {
    position: relative;
    .cur {
      display: none;
    }
    .container {
      position: absolute;
      right: 280px;
      bottom: 40px;
    }
    .list {
      font-size: 20px;
      color: #fff;
      span {
        font-size: 26px;
        text-align: center;
        padding-left: 70px;
        padding-right: 40px;
      }
    }
    .team {
      background: url('../../../../assets/img/legend/team.png') no-repeat;
      background-size: 100% 100%;
      width: 370px;
      height: 80px;
      line-height: 80px;
      z-index: 20;
      i {
        font-size: 26px;
        color: #6ad989;
        padding-right: 10px;
      }
    }
    .per {
      background: url('../../../../assets/img/legend/per.png') no-repeat;
      background-size: 100% 100%;
      width: 370px;
      height: 80px;
      line-height: 80px;
      margin-top: -18px;
      i {
        font-size: 26px;
        color: #cc9d45;
        padding-right: 10px;
      }
    }
  }
}
</style>


